package com.appspot.categoryeditor.model;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.InverseModelListRef;
import org.slim3.datastore.Model;
import org.slim3.datastore.Sort;

import com.appspot.categoryeditor.meta.CategoryMeta;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Query.SortDirection;

@Model
public class Folder {

	@Attribute(primaryKey = true)
	private Key id;

	private long order;
		
	@Attribute(persistent = false)
	private InverseModelListRef<Category, Folder> categoriesRefs 
		= new InverseModelListRef<Category, Folder>(
			Category.class,
			CategoryMeta.get().folderRef.getName(),
			this,
			new Sort(
					CategoryMeta.get().order.getName(),
					SortDirection.ASCENDING));

	@Attribute(version = true)
	private long version;

	public Key getId() {
		return id;
	}

	public void setId(Key id) {
		this.id = id;
	}

	public long getOrder() {
		return order;
	}

	public void setOrder(long order) {
		this.order = order;
	}

	public long getVersion() {
		return version;
	}

	public void setVersion(long version) {
		this.version = version;
	}

	public InverseModelListRef<Category, Folder> getCategoriesRefs() {
		return categoriesRefs;
	}

}
